package com.youlian.cloud.system.service.impl;

import com.youlian.cloud.core.response.ResponseCommonModel;
import com.youlian.cloud.core.bean.ExceptionHandle;
import com.youlian.cloud.system.dao.IGatewayLogDao;
import com.youlian.cloud.system.dao.entity.GatewayLogEntity;
import com.youlian.cloud.system.service.IGatewayLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author : liukx
 * @create : 2018/8/14 19:16
 * @email : liukx@elab-plus.com
 */
@RestController
@RequestMapping(value = "/gatewayLog")
@Api(value = "网关日志", description = "网关错误日志记录", tags = {"网关模块"})
//@EnableAsync
public class GatewayLogServiceImpl implements IGatewayLogService {

    @Autowired
    private IGatewayLogDao gatewayLogDao;

//    @Async
    @Override
    @Transactional(rollbackFor = Exception.class)
    @PostMapping(value = "/insert", produces = "application/json;charset=UTF-8")
    @ExceptionHandle(username = "liukx", ModuleName = GatewayLogServiceImpl.class)
    @ApiOperation(value = "网关错误日志上报", notes = "错误日志", nickname = "liukx")
    public ResponseCommonModel insertData(@RequestBody @Valid GatewayLogEntity entity) throws Exception {
        ResponseCommonModel responseCommonModel = new ResponseCommonModel();
        int id = gatewayLogDao.insert(entity);
        responseCommonModel.setId(id + "");
        return responseCommonModel;
    }

}
